class Solution {
    public:
        long long countBadPairs(vector<int>& nums) {
            int n=nums.size();
            long long ans = (long long)n * (n - 1) / 2;
            unordered_map<int,int> cnt;
            vector<int> num(n);
            for(int j=0;j<n;j++){
                num[j]=nums[j]-j;
                ans -= cnt[num[j]]++;
            }
            return ans;
        }
    };